#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e4 + 10, M = 2e4 + 10;

int n, m, s, t;

int p[N];

int maxv;

struct Edge
{
	int a, b, w;
	bool operator< (const Edge &t)
	{
		return w < t.w;
	}
}edges[M];

int find(int x)
{
	if (p[x] != x) p[x] = find(p[x]);
	return p[x];
}

int kruskal()
{
	sort(edges, edges + m);
	
	for (int i = 0; i < m; i ++ )
	{
		Edge e = edges[i];
		int a = e.a, b = e.b, w = e.w;
		
		int pa = find(a), pb = find(b);
		
		if (pa == pb) continue;
		
		p[pa] = pb;
		
		maxv = max(w, maxv);
		
		int ps = find(s), pt = find(t);
		
		if (ps == pt) return maxv;
	}
}



int main()
{
	cin >> n >> m >> s >> t;
	
	for (int i = 1; i <= n; i ++ ) p[i] = i;
	
	for (int i = 0; i < m; i ++ )
	{
		int a, b, w;
		cin >> a >> b >> w;
		
		edges[i] = {a, b, w};
	}
	
	int t = kruskal();
	
	cout << t << endl;
	
	return 0;
}